import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:mes_app/color/hex.dart' show HexColor;
import 'package:mes_app/components/home/home.dart';
import 'package:mes_app/ui/keep_alive.dart' show KeepAliveWrapperView;

import 'controller.dart';

class HomePage extends GetView<HomeController> {
  const HomePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: HexColor(HexColor.colorF9f9),
      body: Obx(
        () => IndexedStack(
          index: controller.index.value,
          children: [
            KeepAliveWrapperView(
              child: const HomeJobView(),
              callback: () {
                Get.lazyPut(() => HomeJobController());
              },
            ),
            KeepAliveWrapperView(
              child: const HomeInOutStorageView(),
              callback: () {
                Get.lazyPut(() => HomeInOutStorageController());
              },
            ),
            KeepAliveWrapperView(
              child: const HomeHomeWorkbenchView(),
              callback: () {
                Get.lazyPut(() => HomeWorkbenchController());
              },
            ),
            KeepAliveWrapperView(
              child: const HomeMessageView(),
              callback: () {
                Get.lazyPut(() => HomeMessageController());
              },
            ),
            KeepAliveWrapperView(
              child: const HomeMineView(),
              callback: () {
                Get.lazyPut(() => HomeMineController());
              },
            ),
          ],
        ),
      ),
      bottomNavigationBar: SafeArea(
        bottom: true,
        child: Obx(
          () => BottomNavigationBar(
            items: const [
              BottomNavigationBarItem(
                icon: Icon(CupertinoIcons.home),
                label: '报工',
              ),
              BottomNavigationBarItem(
                icon: Icon(CupertinoIcons.person_badge_plus_fill),
                label: '出入库',
              ),
              BottomNavigationBarItem(
                icon: Icon(CupertinoIcons.rectangle_fill_on_rectangle_fill),
                label: '工作台',
              ),
              BottomNavigationBarItem(
                icon: Icon(CupertinoIcons.arrow_2_circlepath_circle_fill),
                label: '消息',
              ),
              BottomNavigationBarItem(
                icon: Icon(CupertinoIcons.person_circle),
                label: '我的',
              ),
            ],
            unselectedFontSize: 14.sp,
            showUnselectedLabels: true,
            selectedFontSize: 14.sp,
            showSelectedLabels: true,
            iconSize: 24,
            type: BottomNavigationBarType.fixed,
            currentIndex: controller.index.value,
            landscapeLayout: BottomNavigationBarLandscapeLayout.linear,
            selectedItemColor: HexColor(HexColor.colorE58c),
            unselectedItemColor: HexColor(HexColor.colorCccc),
            backgroundColor: Colors.white,
            onTap: (int index) {
              controller.index.value = index;
            },
          ),
        ),
      ),
    );
  }
}
